#!/usr/local/bin/perl -w
use strict;
use Template;
require JCL;
#use CGI;

$|=1;
print "Content-type: text/html\n\n";

my $file = 'select.html';

my $date_ref = &JCL::get_date_list('/home/ftpuser/'); 
#print "$_\n" foreach @$date_ref;
my %date_jobs;

foreach (@$date_ref) {
   $date_jobs{$_} = &JCL::get_file_list("/home/ftpuser/$_/"); 
#  print "date=$_\n";
#  print "jobs=\n";
#  my $job_ref = $date_jobs{$_};
#  print "$_ " foreach @$job_ref;
}

my $today;
my $hhmm = &JCL::date_time('hhmm');
if ($hhmm <= 830) {
  $today = &JCL::date_time('yesterday');
}
else {
  $today = &JCL::date_time('today');
}
$date_jobs{$today} = &JCL::get_today_file_list;


my $vars = {
    datelist    => $date_ref,
    date_jobs   => \%date_jobs,
###               must passing array ref. to template toolkit not array
#    'cgi'      => CGI->new(),
};


my $template = Template->new({
    INCLUDE_PATH => '/usr/lib/cgi-bin/src:/usr/lib/cgi-bin/lib',
    PRE_PROCESS  => 'config',
});

$template->process($file, $vars)
    || die $template->error();

